﻿using System;
using System.IO;
using System.Web;
using Alserve.Ffl.Data;

namespace Alserve.Ffl
{
    public class FflCommon
    {
        public FflCommon()
        {
        }

        public static String ImageLocation(Int32 espnPlayerRef, Int32 clubId)
        {
            String returnValue = String.Empty;
            if (File.Exists(HttpContext.Current.Server.MapPath("~/ffl/images/players/" + espnPlayerRef.ToString() + ".jpg")))
            {
                returnValue = "~/ffl/images/players/" + espnPlayerRef.ToString() + ".jpg";
            }
            else
            {
                returnValue = "~/ffl/images/clubs/" + clubId.ToString()  + ".png";
            }
            return returnValue;
        }

        public static String GetTextBetween(String fullText, String start, String end)
        {
            String returnValue = String.Empty;
            if (fullText.IndexOf(start) != -1 && fullText.IndexOf(end) != -1)
            {
                returnValue = fullText.Substring(fullText.IndexOf(start) + start.Length);
                returnValue = returnValue.Substring(0, returnValue.IndexOf(end));
            }
            return returnValue;
        }

        public static String GetTextBefore(String fullText, String end)
        {
            String returnValue = String.Empty;
            if (fullText.IndexOf(end) != -1)
            {
                returnValue = fullText.Substring(0, fullText.IndexOf(end));
            }
            return returnValue;
        }

        public static String GetTextAfter(String fullText, String start)
        {
            String returnValue = String.Empty;
            if (fullText.IndexOf(start) != -1)
            {
                returnValue = fullText.Substring(fullText.IndexOf(start) + start.Length);
            }
            return returnValue;
        }

        public static Boolean InRunning()
        {
            Skip thisSkip = new Skip();
            thisSkip.Where.Keyword.Value = "Status";
            thisSkip.Where.SkipNumber.Value = 1;
            Boolean returnValue = thisSkip.Query.Load();
            return returnValue;
        }
    }
}